
#import "AddCouponViewController.h"
#import "AddCouponDetailVewController.h"
#import "Const.h"

#import "CompanyChoiceViewController.h"
#import "StringTool.h"
#import "CouponData.h"
@implementation AddCouponViewController


@synthesize mainText;
@synthesize couponDic;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}


#pragma mark - Button Maker
-(void)pressedBack
{
	[self.navigationController popViewControllerAnimated:YES];
}
/*
 -(void)makeCustomizeBackButton
 {
 
 UIImage *img = [UIImage imageNamed:@"Top_back_button.png"];
 UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
 backBtn.frame = CGRectMake(0, 0, 24, 44);
 [backBtn setImage:img forState:UIControlStateNormal];
 [backBtn addTarget:self action:@selector(pressedBack) forControlEvents:UIControlEventTouchUpInside];
 
 UIBarButtonItem *back = [[[UIBarButtonItem alloc] initWithCustomView:backBtn] autorelease];
 
 self.navigationItem.leftBarButtonItem = back;	
 }
 */
-(void)remaker{
    NSLog(@"--");
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
	stringTool=[[StringTool alloc]init];
    [super viewDidLoad];
    scrollView.contentSize =CGSizeMake(320, 430);
	
    
    
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:NAVI_R green:NAVI_G blue:NAVI_B alpha:NAVI_A];
    
    self.navigationItem.leftBarButtonItem = refreshButton;
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


-(IBAction)companyChoice:(id)sender{
    CompanyChoiceViewController* companyChoiceViewController = [[CompanyChoiceViewController alloc] initWithNibName:@"CompanyChoiceViewController" bundle:nil];
	self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:companyChoiceViewController animated:YES];
	self.hidesBottomBarWhenPushed = NO;
    
}

-(IBAction)send:(id)sender{
    CouponData* coupondata = [[CouponData alloc]init];
    
    
    AddCouponDetailVewController* addCouponDetailVewController = [[AddCouponDetailVewController alloc] initWithNibName:@"AddCouponDetailVewController" bundle:nil];
    
    [addCouponDetailVewController setCouponData:coupondata];
	self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:addCouponDetailVewController animated:YES];
	self.hidesBottomBarWhenPushed = NO;
}
-(void)alertPannel:(NSString*)string{
	UIAlertView  *alertView = [[UIAlertView alloc]
							   initWithTitle:@"잘못된문자열"
							   message:[NSString stringWithFormat:@"%@",string]
							   delegate:nil
							   cancelButtonTitle:@"확인"
							   otherButtonTitles:nil];
	[alertView show];
	[alertView release]; 
}
-(IBAction)PasteClick{
	int i=0;
	UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
	NSString* TempString=[appPasteBoard string];
	TempString=@"[티켓몬스터/불고기브라더스]\n2011.05.31~2011.08.30\n티켓:qkswnsrl23525\n(강남역 1장)\n\n[티켓몬스터/불고기브라더스]\n2011.05.31~2011.08.30\n티켓:zovo12525\n(강남역 1장)\n\n[티켓몬스터/불고기브라더스]\n2011.05.31~2011.08.30\n티켓:q12345l23525\n(강남역 1장)";
	if(TempString==NULL)[self alertPannel:@"복사된 값이 없습니다."];
	else if([stringTool CheckString:[NSString stringWithFormat:@"%@%@",mainText.text,TempString]]==YES){
		couponDic=[[NSMutableDictionary alloc]initWithDictionary:[stringTool StringToDic:[NSString stringWithFormat:@"%@%@",mainText.text,TempString]]];
		[mainText setText:[NSString stringWithFormat:@"%@%@\n\n",mainText.text,TempString]];
		NSLog(@"%@",couponDic);
		for(NSString* a in [couponDic objectForKey:@"CouponNum"])
			i++;
		[label setText:[NSString stringWithFormat:@"Add %d Coupon",i]];
	}
	else{
		[self alertPannel:@"잘못된문자열!!"];
		NSLog(@"%@",couponDic);
	}
	
	
}


@end
